package com.yjt.gcss.gddw.modules.uiPlds;

import java.util.Hashtable;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.MatchMode;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yjt.common.easyui.datagrid.DataGridDTO;
import com.yjt.common.easyui.datagrid.DataGridJsonDTO;
import com.yjt.common.tools.StringUtil;
import com.yjt.common.tools.TimeUtil;
import com.yjt.gcss.gddw.common.bean.domain.UiPlds;
import com.yjt.gcss.gddw.common.dao.UiPldsDao;

@Service(UiPldsService.BEAN_PACKAGE_NAME)
@Transactional(readOnly=true)
public class UiPldsService {

	public static final String BEAN_PACKAGE_NAME = "com.yjt.gcss.gddw.modules.uiPlds.UiPldsService";
	
	@Resource(name = UiPldsDao.BEAN_PACKAGE_NAME)
	private UiPldsDao uiPldsDao;
	
	public DataGridJsonDTO query(DataGridDTO _dataGridDto, UiPlds queryModel) {
		Hashtable<String, String> paramsTbl = new Hashtable<String, String>();
		//交易日期
		if(!StringUtil.isEmpty(queryModel.getQuery_start_date_createDate())){
			paramsTbl.put("query_start_date_createDate", TimeUtil.changeStrTimeFormat(queryModel.getQuery_start_date_createDate(), "yyyy-MM-dd", "yyyyMMdd"));
			uiPldsDao.enableFilter("uiPldsFilterByCreateDateStartDate", paramsTbl);
			paramsTbl.clear();
		}
		if(!StringUtil.isEmpty(queryModel.getQuery_end_date_createDate())){
			paramsTbl.put("query_end_date_createDate", TimeUtil.changeStrTimeFormat(queryModel.getQuery_end_date_createDate(), "yyyy-MM-dd", "yyyyMMdd"));
			uiPldsDao.enableFilter("uiPldsFilterByCreateDateEndDate", paramsTbl);
			paramsTbl.clear();
		}
		String fileId = queryModel.getFileId();
		if(StringUtils.isNoneBlank(fileId)) {
			paramsTbl.put("fileId", queryModel.getFileId());
			//fileId不再作为模糊查询的条件
			queryModel.setFileId(null);
			uiPldsDao.enableFilter("uiPldsFilterByFileId", paramsTbl);
			paramsTbl.clear();
		}
		DataGridJsonDTO result = uiPldsDao.getBeansByBeanForPager(queryModel, MatchMode.ANYWHERE, _dataGridDto, true);
		if(StringUtils.isNoneBlank(fileId)) {
			uiPldsDao.disableFilter("uiPldsFilterByFileId");
		}
		if(!StringUtil.isEmpty(queryModel.getQuery_start_date_createDate())){
			uiPldsDao.disableFilter("uiPldsFilterByCreateDateStartDate");
		}
		if(!StringUtil.isEmpty(queryModel.getQuery_end_date_createDate())){
			uiPldsDao.disableFilter("uiPldsFilterByCreateDateEndDate");
		}
		return result;
	}
	
	public UiPlds getUiPldsByQueryModel(UiPlds queryModel) {
		return uiPldsDao.getBeanByBean(queryModel, MatchMode.ANYWHERE);
	}
}
